package com.vis.mybatisflex.domain.sys;

import java.text.MessageFormat;

/**
 * 系统业务相关错误信息载体
 */
public class ServiceException extends RuntimeException {
    //错误代码
    private int code = 500;
    //消息内容
    private String message = "操作失败";

    public ServiceException(String message) {
        this.message = message;
    }

    public ServiceException(String message, Object... argArray) {
        this.message = MessageFormat.format(message, argArray);
    }

    public ServiceException(int code) {
        this.code = code;
    }

    public ServiceException(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ServiceException(MSG msg) {
        this.code = msg.code();
        this.message = msg.message();
    }

    public ServiceException(MSG msg, String appendMsg) {
        this.code = msg.code();
        this.message = msg.message() + appendMsg;
    }

    public SRS<Object> getResponse() {
        return SRS.byError().code(code).message(message);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

}
